#ifndef ECARX_NET_UTILS
#define ECARX_NET_UTILS
#include <cstdint>
#include <vector>
#include <string.h>
#include "common.h"
namespace ecarx::transfer::utils {

inline bool isIPCPSignal(uint32_t signalId){
    return (signalId & (uint32_t)SignalType::SIGNAL) == (uint32_t)SignalType::SIGNAL;
}

inline bool isCBPASignal(uint32_t signalId){
    return (signalId & (uint32_t)SignalType::CBPA) == (uint32_t)SignalType::CBPA;
}

inline bool isSomeIPSignal(uint32_t signalId){
    return (signalId & (uint32_t)SignalType::SOMEIP) == (uint32_t)SignalType::SOMEIP;
}

inline bool isReadable(uint32_t signalId){
    return (signalId & (uint32_t)SignalAccess::READ) == (uint32_t)SignalAccess::READ;
}

inline bool isWriteable(uint32_t signalId){
    return (signalId & (uint32_t)SignalAccess::WRITE) == (uint32_t)SignalAccess::WRITE;
}


inline bool isWriteableSignal(uint32_t signal){
    return isIPCPSignal(signal) && isWriteable(signal);
}
inline bool isWriteableCBPASignal(uint32_t signal){
    return isCBPASignal(signal) && isWriteable(signal);
}





template <typename T, size_t N = sizeof(T)>
std::vector<uint8_t> toBytes(T && value) {
    std::vector<uint8_t> data;
    data.resize(N, 0);
    memcpy(data.data(), &value, N);
    return data;
}

template <typename T, size_t N = sizeof(T)>
inline T toValue(const std::vector<uint8_t>& data) {
    T value;
    memcpy(&value, data.data(), N);
    return value;
}


}
#endif

